/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */

function helper(leftNode,rightNode){
    // 要比较两个节点是否对称，
    // 1.左边节点的左子节点值要等于右边节点的右子节点值 (外侧)
    // 2.左边节点的右子节点值要等于右边节点的左子节点值 (内侧)

    // 一些特殊情况，提前返回
    if(leftNode===null && rightNode===null) return true
    if((leftNode===null && rightNode !==null)||(leftNode!==null && rightNode ===null)) return false
    if(leftNode.val !== rightNode.val) return false

    // 左右子树比较
    let outSide=helper(leftNode.left,rightNode.right)
    let inSide=helper(leftNode.right,rightNode.left)
    return outSide && inSide
}

/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isSymmetric = function(root) {
    if(root===null) return true
    return helper(root.left,root.right)
};